﻿using CastingWellEquipmentGUI.Config;
using CastingWellEquipmentGUI.Utils;
using CastingWellEquipmentGUI.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CastingWellEquipmentGUI.View
{
    /// <summary>
    /// Main.xaml 的交互逻辑
    /// </summary>
    public partial class Main : Window
    {

        public Main()
        {
            InitializeComponent();
            XyhUtils.PermissionControl(this, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
            
        }


        private bool AltKeyDown = false;

        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Min_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }
        /// <summary>
        /// 最大化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Max_Click(object sender, RoutedEventArgs e)
        {
            if (WindowState == WindowState.Normal)
            {
                WindowState = WindowState.Maximized;
            }
            else
            {
                WindowState = WindowState.Normal;
            }
        }

        private void MainForm_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
            if (key == Key.LeftAlt || key == Key.RightAlt || key == Key.F4)
            {
                AltKeyDown = true;
            }
            if (key == Key.F4 && AltKeyDown)
            {
                e.Handled = true;
            }
        }

        private void MainForm_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
            if (key == Key.LeftAlt || key == Key.RightAlt)
            {
                AltKeyDown = false;
                return;
            }
        }

        private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            System.Windows.Forms.Application.ExitThread();
            Environment.Exit(0);
        }

        private void Border_CalculationRuler_Loaded(object sender, RoutedEventArgs e)
        {
            double SH = Border_CalculationRuler.ActualHeight;
            double SW = Border_CalculationRuler.ActualWidth;
            double baseH = 527;
            double scaleH = baseH / SH;
            contentcontrol1.Width = scaleH * SW;
            contentcontrol1.Height = SH;
            //Image_CloseNet.Width = Image_CloseNet.Width*1.25;
            //Image_CloseNet.Height = contentcontrol1.Height * 1.25;
        }

        private void Alarm_AlarmUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            string FormName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
            string PermissionsName = "系统主页面";
            SystemConfig.AnalysisFormControlStructureGenerationPermission(FormName, PermissionsName, this);
        }
    }
}
